var limsTest = Gikam.getPageObject({

    getEditListColumns : function() {
        return [ {
            checkbox : true
        }, {
            index : true
        }, {
            field : 'testCode',
            title : 'T_LIMS_TEST.TESTCODE',
            validators: ['notEmpty'],
        }, {
            field : 'testName',
            title : 'T_LIMS_TEST.TESTNAME',
            width : 140,
            validators: ['notEmpty'],
            editor: true,
        }, {
            field : 'testCatCode',
            title : 'T_LIMS_TEST.TESTCATCODE',
            type: 'select',
            search: true,
            width: 160,
            validators: ['notEmpty'],
            firstBlank: false,
            category: 'sys',
            param: {
                codeCategoryId: 'testCategory'
            },
            editor: true
        }, {
            field : 'personName',
            title : 'T_LIMS_TEST.PERSONNAME',
            width: 400,
        }, {
            field : 'testerName',
            title : 'T_LIMS_TEST.TESTERNAME',
            width: 400,
        }, {
            field : 'cycleHours',
            title : 'T_LIMS_TEST.CYCLEHOURS',
            editor: true,
            validators: ['integer', 'numRange(0,)'],
        } ];
    },

    getBaseInfoFormFields: function () {
        return [{
            field: 'testCode',
            title: 'T_LIMS_TEST.TESTCODE',
            preInsert: true,
            validators: ['unique[/secure/basemodule/coredata/tests/action/validate-unique]'],
        }, {
            field: 'testName',
            title: 'T_LIMS_TEST.TESTNAME',
            preInsert: true
        }, {
            field: 'testCatCode',
            title: 'T_LIMS_TEST.TESTCATCODE',
            type: 'select',
            firstBlank : false,
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'testCategory'
            },
            preInsert: true
        }];
    },

    getTestMethodColumns : function() {
        return [ {
            checkbox : true
        }, {
            index : true
        }, {
            field : 'activatedFlag',
            title : 'T_LIMS_TEST_METHOD.ACTIVATEDFLAG',
            type: 'simpleCheckbox',
            width: 160,
            editor: true
        }, {
            field : 'defaultMethod',
            title : 'T_LIMS_TEST_METHOD.DEFAULTMETHOD',
            type: 'select',
            search: true,
            width: 160,
            category: 'sys',
            param: {
                codeCategoryId: 'yesOrNo'
            },
            editor: true
        }, {
            field: 'ext$.methodcode',
            title: 'T_LIMS_METHOD.METHODCODE',
            width: 160,
        }, {
            field: 'ext$.methoddesc',
            title: 'T_LIMS_METHOD.METHODDESC',
            width: 160,
        }, {
            field : 'derivativeTypeName',
            title : 'T_LIMS_TEST_METHOD.DERIVATIVETYPENAME',
            editor: true,
            type: 'choose',
            category: 'sampleType',
            single: true,
            width: 160,
            onBeforeChoose: function () {
                return {
                    filter_derivativeType: '1'
                }
            },
            onAfterChoose: function (rows, index) {
                if (rows) {
                    this.setData({
                        index: index,
                        derivativeType: rows[0].sampleTypeCode,
                        derivativeTypeName: rows[0].sampleTypeName
                    })
                }
            },
            onClean: function (field, value, index) {
                this.setData({
                    index: index,
                    derivativeType: '',
                    derivativeTypeName: ''
                })
            }
        } ];
    },

    getAnalyteFormFields: function () {
        return [{
            field: 'analyte',
            title: 'T_LIMS_TEST_METHOD_ANALYTE.ANALYTE',
            preInsert: true,
            validators: ['notEmpty'],
        }, {
            field: 'sorter',
            title: 'T_LIMS_TEST_METHOD_ANALYTE.SORTER',
            preInsert: true,
            validators: ['integer', 'numRange(0,1000)', 'notEmpty']
        }];
    },

    getAnalisisItemColumns : function() {
        return [ {
            checkbox : true
        }, {index: true},{
            field: 'sorter',
            title: 'T_LIMS_TEST_METHOD_ANALYTE.SORTER',
            editor: true,
            validators: ['integer', 'notEmpty'],
        }, {
            field : 'analyte',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.ANALYTE',
            width: 160,
        }, {
            field : 'formula',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.FORMULA',
            width: 160,
            formatter: function (index, value, row) {
                return Gikam.printf('<a href="javascript:;" onclick="limsTest.editPage.popFormula(\'{index}\')">{name}</a>', {
                    index: index,
                    name: Gikam.isEmpty(value) ? Gikam.propI18N('MODULE.COREDATA.TEST.TIP.NO_MAINTENANCE') : Gikam.propI18N('MODULE.COREDATA.TEST.TIP.MAINTENANCE')
                });
            }
        }, {
            field : 'unit',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.UNIT',
            width: 100,
            editor: true,
            type: 'select',
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'unitCategory'
            },
        }, {
            field : 'picture',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.PICTURE',
            editor: true,
            type: 'choose',
            category: 'rounding-rule',
            onAfterChoose: function (back, index) {
                if (back) {
                    this.setData({
                        index: index,
                        'picture': back
                    })
                }
            },
        }, {
            field : 'defaultResult',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.DEFAULTRESULT',
            editor: true,
        }, {
            field : 'analType',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.ANALTYPE',
            editor: true,
            type: 'select',
            category: 'sys',
            width: 160,
            firstBlank: false,
            param: {
                codeCategoryId: 'analyteResultCategory'
            },
        }, {
            field : 'taskFlag',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.TASKFLAG',
            type: 'simpleCheckbox',
            width: 110,
            editor: true
        }, {
            field : 'taskManageFlag',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.TASKMANAGEFLAG',
            type: 'simpleCheckbox',
            width: 110,
            editor: true
        }, {
            field : 'writeFlag',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.WRITEFLAG',
            type: 'simpleCheckbox',
            width: 110,
            editor: true
        }, {
            field : 'editFlag',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.EDITFLAG',
            type: 'simpleCheckbox',
            width: 110,
            editor: true
        }, {
            field : 'hideFlag',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.HIDEFLAG',
            type: 'simpleCheckbox',
            width: 110,
            editor: true
        }, {
            field : 'inherit',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.INHERIT',
            type: 'simpleCheckbox',
            width: 110,
            editor: true
        }, {
            field : 'possibleFinal',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.POSSIBLEFINAL',
            width: 160,
            editor: true,
            type: 'choose',
            category: 'possibleResult',
            onAfterChoose: function (rows, index) {
                let activedRow = this.getActivedRow();
                Gikam.postSync(limsTest.possibleResultsUrl + '/queries', Gikam.getJsonWrapper({
                    f: {
                        analyteId_EQ: activedRow.id,
                        testMethodId_EQ: activedRow.testMethodId
                    },
                    n: -1, s: -1
                })).done(function (data) {
                    if(Gikam.isNotEmpty(data.rows)){
                        var possibleFinal = data.rows.map(function (item) {
                            return item.originalResult;
                        }).join("/");
                        if (activedRow.possibleFinal !== possibleFinal) {
                            Gikam.getComp('analyte-list-grid').setData({
                                possibleFinal: possibleFinal,
                                id: activedRow.id
                            });
                        }
                    }
                });
            },
            onBeforeChoose: function () {
                return {
                    analyteId_EQ: this.getActivedRow().id,
                    testMethodId_EQ: this.getActivedRow().testMethodId,
                    analType: this.getActivedRow().analType
                }
            },
            onClean : function (field, value, index) {
                var _this = this;
                let row = this.getData()[index];
                var delUrl = Gikam.printf(limsTest.possibleResultsUrl + '/deleteByAnalyteId/{analyteId}', {
                    analyteId: row.id
                })
                workspace.window.showMask();
                Gikam.del(delUrl).done(function () {
                    _this.setData({
                        index : index,
                        possibleFinal : ''
                    })
                }).always(function () {
                    workspace.window.closeMask();
                })
            }
            // cleanable: false
        } ];
    },

    getMaterialItemColumns : function() {
        return [ {
            checkbox : true
        }, {index: true},{
            field : 'matCode',
            title : 'T_LIMS_TEST_METHOD_MATERIAL.MATCODE',
            width : 160,
        }, {
            field : 'matName',
            title : 'T_LIMS_TEST_METHOD_MATERIAL.MATNAME',
            width : 160,
        }, {
            field : 'recommendedAmount',
            title : 'T_LIMS_TEST_METHOD_MATERIAL.RECOMMENDEDAMOUNT',
            editor : true
        } ];
    },

    getEquipmentItemColumns : function() {
        return [ {
            checkbox : true
        },{index: true}, {
            field : 'equipCode',
            title : 'T_LIMS_TEST_METHOD_EQUIPMENT.EQUIPCODE',
            width : 160,
        }, {
            field : 'equipName',
            title : 'T_LIMS_TEST_METHOD_EQUIPMENT.EQUIPNAME',
        } ];
    },

    getChooseListColumns : function() {
        return [ {index: true},{
            field : 'testCode',
            title : 'T_LIMS_TEST.TESTCODE',
            width: 120,
        }, {
            field : 'testName',
            title : 'T_LIMS_TEST.TESTNAME',
            width: 120,
        }, {
            field : 'testCatCode',
            title : 'T_LIMS_TEST.TESTCATCODE',
            width: 160,
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'testCategory'
            },
        }, {
            field : 'personName',
            title : 'T_LIMS_TEST.PERSONNAME',
            width: 400,
        }, {
            field : 'testerName',
            title : 'T_LIMS_TEST.TESTERNAME'
        } ];
    },

    getTestChooseListColumns : function() {
        return [ {
            radio : true
        }, {
            field : 'testCode',
            title : 'T_LIMS_TEST.TESTCODE',
            width: 120,
        }, {
            field : 'testName',
            title : 'T_LIMS_TEST.TESTNAME',
            width: 120,
        }, {
            field : 'testCatCode',
            title : 'T_LIMS_TEST.TESTCATCODE',
            width: 160,
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'testCategory'
            },
        }];
    },

    getMethodChooseListColumns : function() {
        return [{
            field: 'ext$.methodcode',
            title: 'T_LIMS_METHOD.METHODCODE',
            width: 160,
        }, {
            field: 'ext$.methoddesc',
            title: 'T_LIMS_METHOD.METHODDESC',
            width: 160,
        }, {
            field: 'defaultMethod',
            title: 'T_LIMS_TEST_METHOD.DEFAULTMETHOD',
            type: 'simpleCheckbox',
            width: 160,
        }, {
            field: 'derivativeTypeName',
            title: 'T_LIMS_TEST_METHOD.DERIVATIVETYPENAME',
            width: 160,
        }];
    },

    getAnalyteChooseListColumns : function() {
        return [{
            field : 'analyte',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.ANALYTE',
            width: 160,
        }, {
            field : 'analType',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.ANALTYPE',
            type: 'select',
            category: 'sys',
            width: 160,
            param: {
                codeCategoryId: 'analyteResultCategory'
            },
        }, {
            field : 'unit',
            title : 'T_LIMS_TEST_METHOD_ANALYTE.UNIT',
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'unitCategory'
            },
        }];
    },

    getPossibleResultChooseListColumns: function () {
        return [{
            field: 'originalResult',
            width: 160,
            title: 'T_LIMS_POSSIBLERESULT.ORIGINALRESULT',
        }, {
            field: 'finalResult',
            width: 160,
            title: 'T_LIMS_POSSIBLERESULT.FINALRESULT',
        }, {
            field: 'judge',
            title: 'T_LIMS_POSSIBLERESULT.JUDGE',
            type: 'select',
            search: true,
            category: 'judgeType',
            styleFormatter : function(row) {
                return {
                    backgroundColor : row.ext$.color
                }
            }
        }];
    },

    getPossibleResultFormFields: function () {
        return [{
            field: 'originalResult',
            title: 'T_LIMS_POSSIBLERESULT.ORIGINALRESULT',
            preInsert: true,
            onChange: function (field, value) {
                this.setData({
                    originalResult: value,
                    finalResult: value
                })
            }
        }, {
            field: 'judge',
            title: 'T_LIMS_POSSIBLERESULT.JUDGE',
            preInsert: true,
            type: 'select',
            search: true,
            firstBlank: false,
            category: 'judgeType'
        }];
    },

    getTestSupplementColumns: function () {
        return [{
            checkbox: true
        },{
            index: true
        }, {
            field: 'orderNo',
            title: 'T_LIMS_TEST_SUPPLEMENT.ORDERNO',
            validators: ['notEmpty', 'integer', 'numRange(0,)'],
            editor: true
        }, {
            field: 'information',
            title: 'T_LIMS_TEST_SUPPLEMENT.INFORMATION',
            validators: ['notEmpty'],
        }, {
            field: 'unit',
            title: 'T_LIMS_TEST_SUPPLEMENT.UNIT',
            editor: true,
            type: 'select',
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'unitCategory'
            },
            // validators: ['notEmpty'],
        }, {
            field: 'defaultValue',
            title: 'T_LIMS_TEST_SUPPLEMENT.DEFAULTVALUE',
            editor: true
        }, {
            field: 'requiredFlag',
            title: 'T_LIMS_TEST_SUPPLEMENT.REQUIREDFLAG',
            type: 'simpleCheckbox',
            editor: true
        }, {
            field: 'syncAnalyteFlag',
            title: 'T_LIMS_TEST_SUPPLEMENT.SYNCANALYTEFLAG',
            width: 150,
            type: 'simpleCheckbox',
            editor: true
        }, {
            field: 'gainAnalyteFlag',
            title: 'T_LIMS_TEST_SUPPLEMENT.GAINANALYTEFLAG',
            width: 150,
            type: 'simpleCheckbox',
            editor: true
        }];
    },

    getTestSupplementFormFields: function (testId) {
        return [{
            field: 'information',
            title: 'T_LIMS_TEST_SUPPLEMENT.INFORMATION',
            preInsert: true,
            validators: ['notEmpty', {
                type: 'unique',
                rule: Gikam.printf(limsTest.testSupplementUrl + '/{testId}/action/test-validate-unique', {
                    testId : testId
                })
            }],
        }, {
            field: 'unit',
            title: 'T_LIMS_TEST_SUPPLEMENT.UNIT',
            preInsert: true,
            type: 'select',
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'unitCategory'
            },
            // validators: ['notEmpty'],
        }, {
            field: 'orderNo',
            title: 'T_LIMS_TEST_SUPPLEMENT.ORDERNO',
            validators: ['notEmpty', 'integer', 'numRange(0,)'],
            preInsert: true
        }, {
            field: 'defaultValue',
            title: 'T_LIMS_TEST_SUPPLEMENT.DEFAULTVALUE',
            preInsert: true
        }, {
            field: 'requiredFlag',
            title: 'T_LIMS_TEST_SUPPLEMENT.REQUIREDFLAG',
            type: 'simpleCheckbox',
            preInsert: true
        }, {
            field: 'syncAnalyteFlag',
            title: 'T_LIMS_TEST_SUPPLEMENT.SYNCANALYTEFLAG',
            type: 'simpleCheckbox',
            preInsert: true
        }, {
            field: 'gainAnalyteFlag',
            title: 'T_LIMS_TEST_SUPPLEMENT.GAINANALYTEFLAG',
            type: 'simpleCheckbox',
            preInsert: true
        } ];
    },

    baseUrl : IFM_CONTEXT + '/secure/basemodule/coredata/tests',
    methodUrl : IFM_CONTEXT + '/secure/basemodule/coredata/test-methods',
    methodMaterialsUrl : IFM_CONTEXT + '/secure/basemodule/coredata/test-method-materials',
    methodEquipmentsUrl : IFM_CONTEXT + '/secure/basemodule/coredata/test-method-equipments',
    methodAnalytesUrl : IFM_CONTEXT + '/secure/basemodule/coredata/test-method-analytes',
    possibleResultsUrl : IFM_CONTEXT + '/secure/basemodule/coredata/possibleresults',
    testSupplementUrl : IFM_CONTEXT + '/secure/basemodule/coredata/test-supplements',
    productPurposeUrl: IFM_CONTEXT + '/secure/basemodule/coredata/product-main-puposes'
});
